package org.csu.mypetstore.web.servlets;

import org.csu.mypetstore.domain.Account;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class UserSignOutServlet extends HttpServlet {
    public static final String MAIN = "/WEB-INF/jsp/catalog/Main.jsp";

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //先取消授权再删除账户属性是为了确保安全
        ((Account)req.getSession().getAttribute("account")).setAuthenticated(false);//取消授权
        req.getSession().removeAttribute("account");//删除账户信息
        req.getSession().removeAttribute("hasViewedCart");
        req.getSession().removeAttribute("cart");

        resp.sendRedirect("main");//返回主页
    }
}
